<template>
  <div>
    <el-button type="primary" icon="el-icon-plus" @click="showDialog('add')">添加用户</el-button>
    <el-table :data="users">
      <el-table-column prop="id" label="ID"></el-table-column>
      <el-table-column prop="name" label="姓名"></el-table-column>
      <el-table-column prop="age" label="年龄"></el-table-column>
      <el-table-column prop="gender" label="性别"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" icon="el-icon-edit" @click="showDialog('edit', scope.row)">编辑</el-button>
          <el-button size="mini" icon="el-icon-delete" @click="deleteUser(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog :visible.sync="dialogVisible" title="编辑用户">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age"></el-input>
        </el-form-item>
        <el-form-item label="性别" prop="gender">
          <el-radio-group v-model="form.gender">
            <el-radio label="male">男</el-radio>
            <el-radio label="female">女</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="saveUser">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      users: [],
      dialogVisible: false,
      form: {}
    }
  },
  created() {
    this.fetchUsers()
  },
  methods: {
    fetchUsers() {
      // 调用后端接口获取用户列表
    },
    showDialog(type, user) {
      if (type === 'add') {
        this.form = {}
      } else {
        this.form = { ...user }
      }
      this.dialogVisible = true
    },
    saveUser() {
      // 保存编辑后的用户信息
    },
    deleteUser(user) {
      // 删除指定用户
    }
  }
}
</script>